﻿using Lan.Dto;
using Lan.ServiceCore.IService;
using Microsoft.AspNetCore.Mvc;
using Model;

namespace Lan.Application.Controllers
{
    [Route("api/radar")]
    [ApiController]
    public class RadarController : BaseController
    {
        private readonly IRadarService _RadarService;

        public RadarController(IRadarService RadarService)
        {
            _RadarService = RadarService;
        }

        [HttpGet("list")]
        public IActionResult QueryRadar([FromQuery] RadarQueryDto parm)
        {
            var response = _RadarService.GetList(parm);
            return Message(response);
        }

        [HttpGet("{Id}")]
        public IActionResult GetRadar(int Id)
        {
            var response = _RadarService.GetInfo(Id);

            var info = response.Adapt<RadarDto>();
            return Message(info);
        }

        [HttpPost]
        public IActionResult AddRadar([FromBody] RadarDto parm)
        {
            var modal = parm.Adapt<RadarModel>().ToCreate(HttpContext);

            var response = _RadarService.AddRadar(modal);

            return Message(response);
        }

        [HttpPut]
        public IActionResult UpdateRadar([FromBody] RadarDto parm)
        {
            var modal = parm.Adapt<RadarModel>().ToUpdate(HttpContext);
            var response = _RadarService.UpdateRadar(modal);

            return ToResponse(response);
        }

        [HttpDelete("delete/{ids}")]
        public IActionResult DeleteRadar([FromRoute] string ids)
        {
            var idArr = Lan.Tools.Tools.SplitAndConvert<int>(ids);

            return ToResponse(_RadarService.DeleteRadar(idArr));
        }
    }
}
